#include				<iostream>
#include				"Menu.hpp"

Menu::Menu(sf::RenderWindow &win)
	:	_window(win)
{
	_zoneVector.push_back(new EventZone(_window, 201.0f, 255.0f, 9.0f, 9.0f, 0, sf::Color::Red, sf::Color(0, 0, 0, 0)));
	_zoneVector.push_back(new EventZone(_window, 201.0f, 280.0f, 9.0f, 9.0f, 0, sf::Color::Red, sf::Color(0, 0, 0, 0)));
	_zoneVector.push_back(new EventZone(_window, 284.0f, 156.0f, 250.0f, 28.0f, 1, sf::Color(0, 0, 0, 0), sf::Color::Black));
	_zoneVector.push_back(new EventZone(_window, 309.0f, 196.0f, 190.0f, 28.0f, 1, sf::Color(0, 0, 0, 0), sf::Color::Black));
	_screenTexture.loadFromFile(MENU_PATH);
	_screen.setTexture(_screenTexture);
	_screen.setPosition(0, 0);
}

Menu::~Menu()
{
}

void					Menu::draw()
{
	_window.draw(_screen);
	for (int i = 0; i < 4; ++i)
		_zoneVector[i]->draw();
}

void					Menu::mouseMoveEvent(sf::Event::MouseMoveEvent &event)
{
	for (int i = 0; i < 4; ++i)
		_zoneVector[i]->mouseOnZone((float)event.x, (float)event.y);
}

bool					Menu::mouseButtonEvent(sf::Event::MouseButtonEvent &event)
{
	char				zoneClicked = -1;

	for (int i = 0; (i < 4 && zoneClicked == -1) ; ++i)
		if (_zoneVector[i]->clickedOnZone())
			zoneClicked = i;
	if (zoneClicked >= 2)
	{
		setGameType(((zoneClicked == 2) ? 0 : 1), _zoneVector[0]->getSelected(), _zoneVector[1]->getSelected());
		return (true);
	}
	return (false);
}

void					Menu::setGameType(bool zoneClicked, bool doubleThree, bool breakableFive)
{
	int					i = 0;

	_gameType |= (zoneClicked << i++);
	_gameType |= (doubleThree << i++);
	_gameType |= (breakableFive << i++);
}

char			const	Menu::getGameType() const
{
	return (_gameType);
}